package com.service;

import com.config.RedissonConfig;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

@Service
public class TimeTaskServiceImpl {

    @Autowired
    private RedissonClient redissonClient;

    @Scheduled(cron = "0/10 * * * * ?")
    public void sendMessage() throws InterruptedException {

        //实例化   一把锁
        RLock rLock=redissonClient.getLock("hello");
        boolean f=rLock.tryLock(3000,5000, TimeUnit.MILLISECONDS) ;


        if (f){
            System.out.println("我获取一把锁，准备发送信息");
        }else{
            System.out.println("我什么都没有获取到锁就退出了");
        }

    }




}
